import { NameSpace } from '../common/utils/utils';
import AppService from '../util/service/app.service';
import api from '../util/service/api';
let ns = NameSpace('public');





//用户登录状态
export const LOGIN_REQ = ns('LOGIN_REQ');
export const LOGIN_SUC = ns('LOGIN_SUC');
export const LOGIN_ERR = ns('LOGIN_ERR');

//登出
export const LOGOUT_SUC = ns('LOGOUT_SUC');
// 登录
export function login(param) {
  let params = Object.assign({}, {}, param);
  return dispatch => {
    dispatch({ type: LOGIN_REQ });
    dispatch({ type: LOGIN_SUC,data:{userName:'userAdmin'} });

    //待实现的真实请求
    AppService.post(`${api.login}`, { ...params }).then(
      res => {
        dispatch({
          type: LOGIN_SUC,
          data:{userName:'userAdmin'},
          // data: res.data,
        });
      },
      err => {
        dispatch({
          type: LOGIN_ERR,
          data: err,
        });
      },
    );
  };
}

// 登出
export function logout(param) {
  let params = Object.assign({}, {}, param);
  return dispatch => {
    //mock请求
    dispatch({ type: LOGOUT_SUC });
    //待实现的真实请求
  };
}

